package com.lhy.tool.database.converter.postgresql;

import com.lhy.tool.database.DbColumnType;
import com.lhy.tool.database.converter.ColumnTypeMappingRule;
import com.lhy.tool.database.converter.common.AbstractDbColumnTypeMapping;

public class PostgreSqlColumnTypeMapping extends AbstractDbColumnTypeMapping {

    public PostgreSqlColumnTypeMapping() {
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("char") || columnType.contains("text") || columnType.contains("json") || columnType.contains("enum"), (columnType) -> DbColumnType.STRING));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("bigint"), (columnType) -> DbColumnType.LONG));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("bit") || columnType.contains("boolean"), (columnType) -> DbColumnType.BOOLEAN));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("int"), (columnType) -> DbColumnType.INTEGER));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("float"), (columnType) -> DbColumnType.FLOAT));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("double"), (columnType) -> DbColumnType.DOUBLE));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("decimal"), (columnType) -> DbColumnType.BIG_DECIMAL));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("date") || columnType.contains("time") || columnType.contains("year"), (columnType) -> DbColumnType.DATE));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("clob"), (columnType) -> DbColumnType.CLOB));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("blob"), (columnType) -> DbColumnType.BYTE_ARRAY));
    }

}
